package com.brspace.qualitycontrol.controller.admin;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.brspace.qualitycontrol.entity.MeetApply;
import com.brspace.qualitycontrol.entity.MeetNotice;
import com.brspace.qualitycontrol.service.MeetNoticeService;
import com.brspace.qualitycontrol.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 会议通知 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2021-04-02
 */
@Api(description = "会议通知")
@CrossOrigin
@RestController
@RequestMapping("/admin/meet-notice")
public class MeetNoticeController {
    @Resource
    private MeetNoticeService meetNoticeService;

    /**
     * 添加会议通知
     * @param meetNotice
     * @return
     */
    @ApiOperation("添加会议通知")
    @PostMapping("addMeetNot")
    public R addMeetNot(MeetNotice meetNotice) {
        meetNotice.setNoticeType("会议");
        return meetNoticeService.addMeetNot(meetNotice);
    }

    /**
     * 会议通知列表
     * @return
     */
    @ApiOperation("会议通知列表")
    @GetMapping("list")
    public R list(){
        List<MeetNotice> list = meetNoticeService.list();
        return R.ok().data("list",list);
    }

    /***
     * 会议通知分页列表
     * @param page
     * @param limit
     * @return
     */
    @ApiOperation("会议通知分页列表")
    @PostMapping("list/{page}/{limit}")
    public R pageList(
            @ApiParam(value = "当前页码",required = true) @PathVariable Long page,
            @ApiParam(value = "每页多少数据", required = true) @PathVariable Long limit
    ){
        Page<MeetNotice> pageParam = new Page<>(page, limit);
        IPage<MeetNotice> pageModel = meetNoticeService.selectPage(pageParam, null);
        List<MeetNotice> records = pageModel.getRecords();
        long total = pageModel.getTotal();
        return R.ok().data("total",total).data("rows",records);
    }

    @ApiOperation(value = "根据id查询会议详情", notes = "根据id查询会议详情")
    @PostMapping("selectById")
    public R selectById(MeetNotice meetNotice){
        MeetNotice byId = meetNoticeService.getById(meetNotice.getId());
        return R.ok().data("data",byId);
    }
}

